package com.qf.mybatis925.mapper;

import com.qf.mybatis925.entity.LoginUser;
import com.qf.mybatis925.entity.TbPermission;
import com.qf.mybatis925.entity.User;
import com.qf.mybatis925.entity.UserDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

public interface UserMapper {
    User login(LoginUser loginUser);

    List<User> list(UserDTO userDTO);

    int batchDelete(List<Integer> ids);

    int add(User user);

    int update(User user);

    @Select("select * from tb_user where username=#{username}")
    LoginUser loginByUsername(String username);

    @Select("SELECT DISTINCT sp.perm_tag\n" +
            "    FROM tb_user_role sur\n" +
            "    inner join tb_role_permission srp\n" +
            "    on sur.role_id = srp.role_id\n" +
            "    inner join tb_permission sp\n" +
            "    on sp.id = srp.perm_id\n" +
            "    where sur.user_id = #{id}")
    Set<TbPermission> selectAuthsById(Integer id);

    @Insert("insert into tb_user(username,password) values(#{username},#{password})")
    void save(User user);
}
